package drds.global_transaction.api.api;

public enum GlobalTransactionStatus
{

	// unknown
	unknown,

	// PHASE 1: can accept new branch registering.
	begin,

	/**
	 * PHASE 2: Running Status: may be changed any time.
	 */

	// committing.
	committing,

	// Retrying globalTransactionCommit after a recoverable failure.
	commit_retrying,

	// rollbacking
	rollbacking,

	// Retrying globalTransactionRollback after a recoverable failure.
	rollback_retrying,

	// rollbacking since timeout
	timeout_rollbacking,

	// Retrying globalTransactionRollback (since timeout) after a recoverable
	// failure.
	timeout_rollback_retrying,

	/**
	 * PHASE 2: Final Status: will NOT change any more.
	 */

	// Finally: global transaction is successfully committed.
	committed,

	// Finally: failed to globalTransactionCommit
	commit_failed,

	// Finally: global transaction is successfully rollbacked.
	rollbacked,

	// Finally: failed to globalTransactionRollback
	rollback_failed,

	// Finally: global transaction is successfully rollbacked since timeout.
	timeout_rollbacked,

	// Finally: failed to globalTransactionRollback since timeout
	timeout_rollback_failed,

	// Not managed in transaction_session map$channelToRpcContextMap any more
	finished;

	public static GlobalTransactionStatus get(byte ordinal)
	{
		return get((int) ordinal);
	}

	public static GlobalTransactionStatus get(int ordinal)
	{
		for (GlobalTransactionStatus globalTransactionStatus : GlobalTransactionStatus.values())
		{
			if (globalTransactionStatus.ordinal() == ordinal)
			{
				return globalTransactionStatus;
			}
		}
		throw new IllegalArgumentException("unknown GlobalTransactionStatus[" + ordinal + "]");
	}
}
